﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Web.Profile;
using System.Xml;

namespace WebSite
{
    public class fun
    {
        // Methods
        public static string banner(string str)
        {
            string sql = "select top 1 * from DB_Model where visible=1";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                str = table.Rows[0]["modelid"].ToString();
            }
            if (str.Trim().ToString() == "")
            {
                str = "0";
            }
            return str.Trim();
        }

        public static string GetGuidRandom(int len)
        {
            string str = ",";
            string str2 = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,-";
            string str3 = "0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6";
            char[] separator = str.ToCharArray();
            char[] chArray2 = str.ToCharArray();
            string[] strArray = str2.Split(separator, str2.Length);
            string[] strArray2 = str3.Split(chArray2, str3.Length);
            string str4 = Guid.NewGuid().ToString();
            for (int i = 0; i < strArray.Length; i++)
            {
                str4 = str4.Replace(strArray[i], strArray2[i]);
            }
            return str4.Substring(0, len);
        }

        public static string geturl(string host_url)
        {
            string str = HttpContext.Current.Request.Url.ToString();
            string str2 = str.Substring(str.IndexOf("//") + 2);
            host_url = "" + str2.Substring(0, str2.IndexOf("/"));
            if (host_url.Trim().ToString() == "")
            {
                host_url = "";
            }
            return host_url.Trim();
        }

        public static string geturl1(string host_url)
        {
            string str = HttpContext.Current.Request.Url.ToString();
            string str2 = str.Substring(str.IndexOf("//") + 2);
            host_url = "http://" + str2.Substring(0, str2.IndexOf("/") + 1);
            host_url = host_url + "cn/";
            if (host_url.Trim().ToString() == "")
            {
                host_url = "";
            }
            return host_url.Trim();
        }

        public static string Left(string sSource, int iLength)
        {
            return sSource.Substring(0, (iLength > sSource.Length) ? sSource.Length : iLength);
        }

        public static string menuinfo(string str, string str1, string str2)
        {
            string sql = "select top 1 * from DB_Class where classid=" + str1.ToString() ;
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                if (str2.ToString() == "1")
                {
                    str = table.Rows[0]["classname"].ToString();
                }
                if (str2.ToString() == "2")
                {
                    str = table.Rows[0]["classcontent"].ToString().Replace("'", "''");
                }
            }
            if (str.Trim().ToString() == "")
            {
                str = "";
            }
            return str.Trim();
        }

        public static string newsclass(string str, string str1, string str2, string str3)
        {
            string sql = "select top 1 * from DB_Newsclass where classid=" + str1.ToString() + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                if ((str2.ToString() == "1") && (str3.ToString() == "1"))
                {
                    str = table.Rows[0]["classname"].ToString();
                }
                if ((str2.ToString() == "2") && (str3.ToString() == "1"))
                {
                    str = table.Rows[0]["classcontent"].ToString();
                }
            }
            if (str.Trim().ToString() == "")
            {
                str = "";
            }
            return str.Trim();
        }

        public static string productclass(string str, string str1, string str2, string str3)
        {
            string sql = "select top 1 * from DB_Productclass where classid=" + str1.ToString() + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                if ((str2.ToString() == "1") && (str3.ToString() == "1"))
                {
                    str = table.Rows[0]["classname"].ToString();
                }
                if ((str2.ToString() == "2") && (str3.ToString() == "1"))
                {
                    str = table.Rows[0]["classcontent"].ToString();
                }
            }
            if (str.Trim().ToString() == "")
            {
                str = "";
            }
            return str.Trim();
        }

        public static string ReadValue(string key)
        {
            XmlDocument document = new XmlDocument();
            document.Load(HttpContext.Current.Server.MapPath("/model.xml"));
            XmlNodeList elementsByTagName = document.GetElementsByTagName(key);
            if (elementsByTagName.Count == 0)
            {
                return "";
            }
            XmlNode node = elementsByTagName[0];
            return node.InnerText;
        }

        public static string shuname(string shuid)
        {
            string str;
            string sql = "select shuxiname from DB_Shuxintype where shuxinid=" + shuid + "";
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                str = table.Rows[0][0].ToString();
            }
            else
            {
                str = "推荐";
            }
            if (str.Trim().ToString() == "")
            {
                str = "推荐";
            }
            return str.Trim();
        }

        public static string tables(string str, string table, string proid)
        {
            string sql = "select top 1 * from " + table + " where proid=" + proid + "";
            DataTable table2 = new DataTable();
            table2 = SQLAccess.GreatDs(sql).Tables[0];
            if (table2.Rows.Count > 0)
            {
                str = "1";
            }
            else
            {
                str = "0";
            }
            if (str.Trim().ToString() == "")
            {
                str = "0";
            }
            return str.Trim();
        }

        public static string weburl(string str, string zjurl, string regname, string regcode)
        {
            zjurl = zjurl + regname;
            zjurl = zjurl.ToLower().Trim();
            zjurl = Left(zjurl.Replace("www.", ""), 15);
            zjurl = zjurl.Replace("0", "a");
            zjurl = zjurl.Replace("1", "b");
            zjurl = zjurl.Replace("2", "c");
            zjurl = zjurl.Replace("3", "d");
            zjurl = zjurl.Replace("4", "e");
            zjurl = zjurl.Replace("5", "f");
            zjurl = zjurl.Replace("6", "g");
            zjurl = zjurl.Replace("7", "h");
            zjurl = zjurl.Replace("8", "i");
            zjurl = zjurl.Replace("9", "j");
            zjurl = zjurl.Replace("a", "48");
            zjurl = zjurl.Replace("b", "49");
            zjurl = zjurl.Replace("c", "55");
            zjurl = zjurl.Replace("d", "56");
            zjurl = zjurl.Replace("e", "66");
            zjurl = zjurl.Replace("f", "69");
            zjurl = zjurl.Replace("g", "76");
            zjurl = zjurl.Replace("h", "75");
            zjurl = zjurl.Replace("i", "88");
            zjurl = zjurl.Replace("j", "89");
            zjurl = zjurl.Replace("k", "20");
            zjurl = zjurl.Replace("l", "61");
            zjurl = zjurl.Replace("m", "22");
            zjurl = zjurl.Replace("n", "23");
            zjurl = zjurl.Replace("o", "24");
            zjurl = zjurl.Replace("p", "25");
            zjurl = zjurl.Replace("q", "26");
            zjurl = zjurl.Replace("r", "17");
            zjurl = zjurl.Replace("s", "28");
            zjurl = zjurl.Replace("t", "29");
            zjurl = zjurl.Replace("u", "30");
            zjurl = zjurl.Replace("v", "31");
            zjurl = zjurl.Replace("w", "39");
            zjurl = zjurl.Replace("x", "33");
            zjurl = zjurl.Replace("y", "34");
            zjurl = zjurl.Replace("z", "35");
            zjurl = zjurl.Replace("-", "36");
            zjurl = zjurl.Replace(".", "38");
            zjurl = zjurl.Replace(":", "40");
            int length = zjurl.Length;
            if (length > 12)
            {
                int startIndex = length - 6;
                zjurl = Left(zjurl, 6) + zjurl.Substring(startIndex, 6);
            }
            long num4 = (Convert.ToInt64(zjurl) * zjurl.Length) + (regname + "http://www.kingdeone.com").Length;
            while (num4 > 0xe8d4a51000L)
            {
                num4 -= 0xe8d4a51000L;
            }
            string str2 = "";
            if (num4.ToString().Length < 12)
            {
                for (int i = 0; i < (num4.ToString().Length - 2); i++)
                {
                    str2 = str2 + "0";
                }
            }
            str = str2 + num4.ToString();
            if (str.Trim().ToString() == "")
            {
                str = "";
            }
            return str.Trim();
        }

    }
}